<?php

namespace App\Console\Commands\Test;

use App\Imports\MImport;
use App\Models\Tmp\TmpC;
use App\Models\Tmp\TmpM;
use App\Imports\UsersImport;
use Illuminate\Console\Command;
use App\Models\QingShanERP\Order;
use App\Models\QingShanERP\OrderPddData;

class Excel extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'pdd-excel';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        try {
            $all = OrderPddData::get();
            foreach ($all as $a) {
                Order::where('id',$a->order_id)->update(['logistics_id'=>$a->logistics_id, 'tracking_number' => $a->tracking_number, 'shipping_time' => $a->shipping_time, 'receive_time' => $a->receive_time]);
                dump($a->id);
            }
            // \Maatwebsite\Excel\Facades\Excel::import(new UsersImport(), 'c.xlsx');
            // dump('success - cccc');
            // \Maatwebsite\Excel\Facades\Excel::import(new MImport(), 'm3.xlsx');
            // dd(1);
            // $all_c = TmpC::pluck('order_sn')->unique()->toArray();
            // // dd($all_c);
            // $all_m = TmpM::pluck('order_sn')->unique()->toArray();
            // // 包含$all_c的元素,不包括$all_m的元素
            // $res = array_diff($all_c, $all_m);
            // // dump($res);
            // $all = [];
            // foreach ($res as $r) {
            //     $a = OrderPddData::where('remark','!=','')->where('remark','like',"%".$r."%")->first();
            //     if (!is_null($a)) {
            //         $all[] = $r;
            //     }
            // }
            // dump($all);
            // dd(count($all));
        } catch (\Throwable $th) {
            dd($th->getMessage());
        }
    }
}
